<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/wesite/view/common/base.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>重置密码</title>
    <%@ include file="/wesite/view/common/common.jsp"%>
    <style type="text/css">
        html,body{background:#f2f2f2;}
        .loginbox.signbox.hide{
            display: none;
        }
        .loginbox.signbox{
            margin:0;
        }
    </style>
</head>
<body>
<input type="hidden" name="loginphone" value="${loginphone}">
<div class="loginbox signbox">
    <div class="login-input">
        <div class="input-text"><span class="text-tit">用户名</span><input name="loginname"  type="text" placeholder="请输入手机号码或用户名"></div>
        <div class="itemTip" id="logintip"></div>
        <div class="input-text"><span class="text-tit">验证码</span><input class="code" name="checkcode" type="number" placeholder="请输入验证码">
            <span class="code-img">
                       		<img id="checkcodeimg" onclick="getcheckcodeimg()"  width="110" height="38" alt="">
                      	</span></div>

    </div>
    <input type="button" value="下一步" onclick="next1()">
</div>
<div class="loginbox signbox hide"  id="password">
    <div class="login-input">
        <div class="input-text"><span class="text-tit">用户名</span><input id="phone" name="phone" type="number"  placeholder="请输入手机号码或用户名"></div>
        <div class="input-text"><span class="text-tit">验证码</span><input class="code" name="smscode" type="number" placeholder="请输入验证码">
            <span class="send"><a href="javascript:tosensms();" id="smsbtn" class="yzm-btn">获取验证码</a></span>
        </div>
        <div class="itemTip" id="itemTip_old"></div>
        <div class="input-text"><span class="text-tit">密码</span><input type="password" name="newpwd" placeholder="请输入密码"></div>

    </div>
    <input type="button" value="完成" onclick="next2()">
</div>
</body>
</html>
<script src="${webctx}/script/common.js"></script>
<script src="${webctx}/script/sms.js"></script>
<script>
    $(function(){
        getcheckcodeimg();
    })
    function getcheckcodeimg(){
        $("#checkcodeimg").attr("src",server+"/validateimg?d="+new Date().getTime());
    }
    var user;
    function checkloginphone(fun){
        var toast = new auiToast({})
        $(".itemTip").text('');
        $w.httpRequest({
            url:"${ctx}/we/user/checkloginphone",
            data:{"loginname":$("[name='loginname']").val()},
            ok:function(ret){
                user=ret.Data;
                fun();
            },fail:function(ret){

                if(ret.MsgCode=='2') toast.fail({
                    title:"账号不存在",
                    duration:1000
                })
                else if(ret.MsgCode=='3') toast.fail({
                    title:"该手机已绑定用户名或输入用户名",
                    duration:1000
                })
                else toast.fail({
                        title:ret.MsgDesc,
                        duration:1000
                    })//$("#logintip").text(ret.MsgDesc);
                return false;
            }
        })
    }
    function next1(){
        checkloginphone(function(){
            $("#phone").val(user.phone).attr({readonly:'true'});
            var toast = new auiToast({})
            if($("[name='checkcode']").val().length<=0) {
                toast.fail({
                    title:"验证码不能为空",
                    duration:1000
                })
                return false;
            }
            $w.httpRequest({
                url:"${ctx}/we/user/checkimgcode",
                data:{"code":$("[name='checkcode']").val()},
                ok:function(ret){
                    if(ret.Data){
                        $(".signbox").hide();
                        $("#password").show();
                        //window.location.href="${ctx}/we/user/resetpassword2";
                    }else toast.fail({
                        title:"验证码错误或失效",
                        duration:1000
                    })
                }
            })

        })
    }
    function tosensms() {
        $w.httpRequest({
            url:"${ctx}/we/user/sendsms",
            data:{"mobile":user.phone},
            ok:function(ret){
                sendsms(user.phone,'findpwd','smsbtn');
            }
        })

    }
    function next2() {
        var dataphone = ($("[name='phone']").val());
        var id = $("[name='id']").val();
        var toast = new auiToast({})
        $w.httpRequest({
            url:"${ctx}/we/user/checksmscode",
            data:{"mobile":user.phone,"smscode":$("[name='smscode']").val()},
            ok:function(ret){
                if(ret.Data=='true'){
                    if ($("[name='newpwd']").val().length<6){
                        toast.fail({
                            title : "请输入6位密码",
                            duration : 1000
                        })

                        return;
                    }
                    if ($("[name='newpwd']").val().length>16){
                        toast.fail({
                            title : "密码不能超过16位数",
                            duration : 1000
                        })
                        return;
                    }
                    $w.httpRequest({
                        url:"${ctx}/we/user/findpwd",
                        data:{"userid":user.id,"phone":user.phone,"smscode":$("[name='smscode']").val(),"newpwd":$("[name='newpwd']").val()},
                        ok:function(ret){
                            window.location.href="${ctx}/we/user/login";
                        }
                    })
                }else toast.fail({
                    title : "验证码错误或失效",
                    duration : 1000
                })
            }
        })

    }
</script>